package hhh.zjh.com.handlerthread;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    Button startButton = null;
    Button endButton = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.startButton = (Button)findViewById(R.id.startButton);
        this.endButton = (Button)findViewById(R.id.endButton);
        startButton.setOnClickListener(new startButtonListener());
        endButton.setOnClickListener(new endButtonListener());

    }

    Handler handler  = new Handler();
public class startButtonListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            handler.post(updateThread);
        }
    }
public class endButtonListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            handler.post(updateThread);
        }
    }
Runnable updateThread = new Runnable() {
    @Override
    public void run() {
        System.out.print("updateThread");
        Log.v("tag","UpdateThread");
        handler.postDelayed(updateThread, 2000);
    }
};
}